/*
 * Copyright (c) 2011-2014, fortiss GmbH.
 * Licensed under the Apache License, Version 2.0.
 *
 * Use, modification and distribution are subject to the terms specified
 * in the accompanying license file LICENSE.txt located at the root directory
 * of this software distribution. A copy is available at
 * http://chromosome.fortiss.org/.
 *
 * This file is part of CHROMOSOME.
 *
 * $Id: loginManagerProcessLogoutNotificationFunction.c 7837 2014-03-14 12:33:13Z wiesmueller $
 */

/**
 * \file
 *         Source file for function loginManagerProcessLogoutNotification in component loginManager.
 *
 * \author
 *         This file has been generated by the CHROMOSOME Modeling Tool (XMT)
 *         (fortiss GmbH).
 */

/******************************************************************************/
/***   Includes                                                             ***/
/******************************************************************************/
#include "xme/core/login/include-gen/loginManagerProcessLogoutNotificationFunction.h"

#include "xme/core/login/include-gen/loginManagerProcessLogoutNotificationFunctionWrapper.h"
#include "xme/core/login/include-gen/loginManagerComponent.h"
#include "xme/core/login/include-gen/loginManagerComponentWrapper.h"
#include "xme/core/login/include-gen/loginManagerManifest.h"

#include "xme/core/logUtils.h"

#include "xme/hal/include/mem.h"

// PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_C_INCLUDES) ENABLED START
#include "xme/core/login/include/loginManager.h"
// PROTECTED REGION END

/******************************************************************************/
/***   Definitions                                                          ***/
/******************************************************************************/

// PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_C_DEFINITIONS) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Variables                                                            ***/
/******************************************************************************/

// PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_C_VARIABLES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Prototypes                                                           ***/
/******************************************************************************/

// PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_C_PROTOTYPES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Implementation                                                       ***/
/******************************************************************************/
xme_status_t
xme_core_login_loginManagerProcessLogoutNotificationFunction_init
(
    xme_core_login_loginManagerComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_INITIALIZE_C) ENABLED START

    // Nothing to do

    XME_UNUSED_PARAMETER(componentConfig);

    return XME_STATUS_SUCCESS;

    // PROTECTED REGION END
}

void
xme_core_login_loginManagerProcessLogoutNotificationFunction_step
(
    xme_core_login_loginManagerComponent_config_t* const componentConfig
)
{
    xme_status_t status[1];
    
    xme_core_topic_pnp_logoutNotification_t portInLogoutNotificationData; // Required port.
    
    (void)xme_hal_mem_set(&portInLogoutNotificationData, 0u, sizeof(xme_core_topic_pnp_logoutNotification_t));
    
    status[0] = xme_core_login_loginManagerComponentWrapper_readPortInLogoutNotification(&portInLogoutNotificationData);
    
    {
        // PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_STEP_C) ENABLED START

        XME_UNUSED_PARAMETER(componentConfig);
        if (XME_STATUS_SUCCESS == status[0])
        {
            status[0] = xme_core_login_loginManager_logoutAcknowledgement(portInLogoutNotificationData.nodeId);
            if (XME_STATUS_SUCCESS != status[0])
            {
                XME_LOG
                (
                    XME_LOG_WARNING,
                    "[LoginManager] Deregisteration of node %d from Login Manager was not successful (code %d)!\n",
                    portInLogoutNotificationData.nodeId, status[0]
                );
            }
        }

        // PROTECTED REGION END
    }
    
    {
        // PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_STEP_2_C) ENABLED START

        // TODO: Check return values of writePort calls here

        // PROTECTED REGION END
    }
}

void
xme_core_login_loginManagerProcessLogoutNotificationFunction_fini
(
    xme_core_login_loginManagerComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_TERMINATE_C) ENABLED START

    // Nothing to do

    XME_UNUSED_PARAMETER(componentConfig);

    // PROTECTED REGION END
}

// PROTECTED REGION ID(XME_CORE_LOGIN_LOGINMANAGERPROCESSLOGOUTNOTIFICATIONFUNCTION_IMPLEMENTATION_C) ENABLED START

// PROTECTED REGION END
